package dialogos;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileNameExtensionFilter;

import datos.Cliente;

import accesoADatos.AccesoADatos;
import paneles.PanelClientes;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ClienteDialogo extends javax.swing.JDialog {
	
	private PanelClientes panelClientes1;
	private boolean opcion;

	/**
	* Auto-generated main method to display this JDialog
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				ClienteDialogo inst = new ClienteDialogo(frame);
				inst.setVisible(true);
			}
		});
	}
	
	public ClienteDialogo(JFrame frame) {
		super(frame,"Agregar Cliente",true);
		initGUI();
	}
	
	public ClienteDialogo(JDialog d) {
		super(d,"Agregar Cliente",true);
		initGUI();
	}

	public ClienteDialogo(JDialog d,Cliente c) {
		super(d,"Agregar Cliente",true);
		initGUI();
		this.panelClientes1.cargarCliente(c);
	}

	private void initGUI() {
		try {
				opcion = false;
				panelClientes1 = new PanelClientes();
				panelClientes1.getBCancelar().addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						bCancelarActionPerformed(evt);
					}
				});
				{
				panelClientes1.getBAceptar().addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						bAceptarActionPerformed(evt);
					}
				});}
				getContentPane().add(panelClientes1, BorderLayout.CENTER);
				panelClientes1.setPreferredSize(new java.awt.Dimension(330, 351));
			pack();
			this.setSize(340, 380);
			this.setLocationRelativeTo(null);
			this.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void bAceptarActionPerformed(ActionEvent evt) {
		this.opcion = true;
		Cliente c=this.panelClientes1.getCliente();
		c.setFoto(this.panelClientes1.getRuta());
		AccesoADatos.getInstance().setObjeto(c);
		this.dispose();
	}
	
	private void bCancelarActionPerformed(ActionEvent evt) {
		this.dispose();
	}
	
	public Cliente getCliente(){
		return (this.panelClientes1.getCliente());
	}

	public boolean getOpcion() {
		return this.opcion;
	}

}
